﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Quakk.Forms
{
    public partial class ConfigForm : Form
    {
        private Configuration config;

        public Configuration Configuration
        {
            get
            {
                return config;
            }
            set
            {
                config = value;
                if (config != null)
                {
                    textBoxUsername.Text = config.Username;
                    textBoxPassword.Text = config.Password;
                }
            }
        }

        public ConfigForm(Configuration config)
        {
            InitializeComponent();
            Configuration = config;
        }

        private void ConfigForm_Resize(object sender, EventArgs e)
        {
            int x = (Width - mainPanel.Width)/2;
            int y = (Height - mainPanel.Height)/2;
            mainPanel.Location = new Point(x, y);
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Configuration = new Configuration
                                {
                                     Username = textBoxUsername.Text, 
                                     Password = textBoxPassword.Text
                                };
            Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ConfigForm_Load(object sender, EventArgs e)
        {
            BackColor = Display.BackgroundColour;
            mainPanel.BackColor = Display.BackgroundColour;
        }
    }
}